package com.chaoyue.web;

import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class loginServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter("name");
		
		ServletContext application = getServletContext();
		
		List<String> nameList = (List<String>) application.getAttribute("nameList");
		if(nameList==null){
			nameList = new ArrayList<String>();
			
		}
		nameList.add(name);
		
		application.setAttribute("nameList", nameList);
		
		HttpSession session =request.getSession();
		session.setAttribute("user", name);
		
		response.sendRedirect("main.jsp");

	}

}
